"""
并发抓取10个url
"""
import requests
from multiprocessing import Process
from concurrent import futures

headers = {
    'User-Agent':
        'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 '
        '(KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36'
}


def crawl_each_tag_books(url):
    response = requests.get(url, headers=headers)
    print(response.status_code, response.content)


# 使用多进程
def crawl_douban_tag_books_use_multiprocess(urls):
    for url in urls:
        p = Process(target=crawl_each_tag_books, args=(url,))
        p.start()


# 使用多线程
def crawl_douban_tag_books_use_multithread(urls):
    threads_pool = futures.ThreadPoolExecutor(max_workers=5)
    for url in urls:
        threads_pool.submit(crawl_each_tag_books, url)


if __name__ == '__main__':
    book_urls = ['https://book.douban.com/tag/%E5%B0%8F%E8%AF%B4',
                 'https://book.douban.com/tag/%E9%9A%8F%E7%AC%94',
                 'https://book.douban.com/tag/%E6%95%A3%E6%96%87',
                 'https://book.douban.com/tag/%E8%AF%97%E6%AD%8C',
                 'https://book.douban.com/tag/%E7%AB%A5%E8%AF%9D',
                 'https://book.douban.com/tag/%E5%90%8D%E8%91%97',
                 'https://book.douban.com/tag/%E6%B8%AF%E5%8F%B0',
                 'https://book.douban.com/tag/%E6%BC%AB%E7%94%BB',
                 'https://book.douban.com/tag/%E6%8E%A8%E7%90%86',
                 'https://book.douban.com/tag/%E9%9D%92%E6%98%A5']
    crawl_douban_tag_books_use_multithread(book_urls)
